package com.gonsin.gview.annotations;

import lombok.Getter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 存储页面上下文信息
 */
@Getter
public class GContext {

    private String viewName;

    private HttpServletRequest request;

    private HttpServletResponse response;

    private Map<String, Object> props;

    private HttpSession session;

    private boolean initialing;

//    /**
//     * 装在这动态gview的内容
//     */
//    private IDynamicHolder dynamicHolder;

    private AtomicInteger index = new AtomicInteger(0);

    public GContext(String viewName, HttpServletRequest request, HttpServletResponse response, Map<String, Object> props, boolean initialing) {
        this.viewName = viewName;
        this.request = request;
        this.response = response;
        this.props = props;
        if(request != null){
            this.session = request.getSession();
        }
        this.initialing = initialing;
    }

    /**
     * 每次获取都会 +1
     */
    public int nextIndex() {
        return index.incrementAndGet();
    }



}
